<?php

/**
 * 自定义公共函数库
 */
if (!function_exists('curl_post')) {
    /**
     * CURL POST 请求
     * Author: Albert3306
     * Date: 2020/6/16
     * @param string        $url
     * @param array|string  $data
     * @param array         $headers
     * @return bool|string
     */
    function curl_post($url, $data, $headers = [])
    {
        $ch = curl_init();
        $res= curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt ($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        $handles = curl_exec($ch);
        curl_close($ch);
        return $handles;
    }
}

if (!function_exists('curl_get')) {
    /**
     * CURL GET 请求
     * Author: Albert3306
     * Date: 2020/6/18
     * @param $url
     * @return bool|string
     */
    function curl_get($url){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        if(curl_errno($curl)){
            return 'ERROR ' . curl_error($curl);
        }
        curl_close($curl);
        return $output;
    }
}
